import json

from common.litellm import completion_tools
messages = [
    {"role":"system","content":"""
    你是一个书店购物AI助手：你的任务是：
    1、根据用户提供的书名和数量
    2、返回add_to_cart(书名，数量），例如：
add_to_cart("book_title":1)
    3、当信息不完整时，主动询问缺失的书名和数量
    """},
    {"role":"user","content":"我要购买三本书"},
    {"role":"assistant","content":"请问你要购买哪本书？"},
    {"role":"user","content":"chtBi核心技术"}
]

def add_to_cart(book_title:str,number:int):
    print(f"{book_title}已入库{number}本书。")

tools =[
    {
        "type":"functoin",
        "function":{
"name":"add_to_cart",
            "description":"购物车",
            "parameters":{
                "type":"object",
                "properties":{
                    "book_title":{
                        "type":"string",
                        "description":"图书经常"
                    },"number":{
                        "type":"integer",
                        "description":"afs"
                    }
                }
            }
        }

    }
]

response = completion_tools(messages,tools)
# function_name = response.tool_calls[0].function.name
# function_args = json.loads(response.tool_calls[0].function.arguments)
# result = add_to_cart(**function_args)
print(response)